/**
 * 
 */
package com.quiz.activity.sections;

import java.util.List;

import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

import com.quiz.activity.R;
import com.quiz.model.Section;
import com.quiz.swipeyTabs.SwipeyTabs;
import com.quiz.swipeyTabs.SwipeyTabsAdapter;


/**
 *
 * @author Brian Boyle
 * Apr 10, 2012
 */
public class SectionsPagerAdapter extends FragmentPagerAdapter implements SwipeyTabsAdapter {

    private List<Section> sections;
    private Context context;
    private ViewPager viewPager;

    public SectionsPagerAdapter(ViewPager viewPager, List<Section> sections, Context context, FragmentManager fm) {
        super(fm);
        this.viewPager = viewPager;
        this.sections = sections;
        this.context = context;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public int getCount() {
        return this.sections.size();
    }


    /**
     * {@inheritDoc}
     */
    public TextView getTab(final int position, SwipeyTabs root) {
        Section section = this.sections.get(position);

        TextView view = (TextView) LayoutInflater.from(this.context).inflate(R.layout.swipey_tab_indicator, root, false);
        view.setText(section.getName());
        view.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                viewPager.setCurrentItem(position);
            }
        });

        return view;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public int getItemPosition(Object object) {
        return POSITION_NONE;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Fragment getItem(int position) {
        Section section = this.sections.get(position);
        SectionFragment fragment = new SectionFragment(this.context, section);
        return fragment;
    }


}
